package ovm.management.menu;

import ovm.entity.MenuEntity;
import ovm.management.AbstractManager;

import javax.persistence.Query;
import java.util.List;

import static ovm.application.MainApplication.navigator;

public class MenuManager extends AbstractManager {

    public static List<MenuEntity> getChildren (Integer id) {
        Query query = em.createQuery("SELECT me FROM MenuEntity me " +
                "WHERE me.parentId = :id AND me.rule <= :rule " +
                "ORDER BY me.orderNumber");
        query.setParameter("id", id);
        query.setParameter("rule", navigator.getCurrentUser());
        return (List<MenuEntity>) query.getResultList();
    }

}
